<?php
namespace AliyunCore;
//include  dirname(app_path()).DIRECTORY_SEPARATOR."extend".'/aliyun-php-sdk-afs-20180112-2/aliyun-php-sdk-afs-20180112 2/aliyun-php-sdk-core/Config.php';
include_once  'aliyun-php-sdk-afs-20180112-2/aliyun-php-sdk-afs-20180112 2/aliyun-php-sdk-core/Config.php';
use afs\Request\V20180112 as Afs;

class VerifyDate
{
    protected $accesskey;
    protected $secret;
    //地域
    protected $area = 'cn-hangzhou';
    //使用产品
    protected $product = 'afs';
    //服务域名
    protected $domain = 'afs.aliyuncs.com';
    //id
    protected $appKey;
    // 请求IP地址
    protected $remoteIp;

    public function getAccessKey()
    {
        return $this->accesskey;
    }
    public function getSecret()
    {
        return $this->secret;
    }
    public function setAccessKey($accessKey)
    {
         $this->accesskey=$accessKey;
    }
    public function setSecret($secret)
    {
        $this->secret=$secret;
    }
    public function getArea()
    {
        return $this->area;
    }
    public function setArea($area)
    {
        $this->area = $area;
    }
    public function getProduct()
    {
        return $this->product;
    }
    public function setProduct($product)
    {
        $this->product = $product;
    }
    public function getDomain()
    {
        return $this->domain;
    }
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }
    public function setAppkey($appKey)
    {
        $this->appKey = $appKey;
    }
    public function getAppkey()
    {
        return $this->appKey;
    }
    public function setRemoteIp($remoteIp)
    {
        $this->remoteIp = $remoteIp;
    }
    public function hetRemoteIp()
    {
        return  $this->remoteIp;
    }

    public function verify($param)
    {
        //YOUR ACCESS_KEY、YOUR ACCESS_SECRET请替换成您的阿里云accesskey id和secret
        $iClientProfile = \DefaultProfile::getProfile($this->area, $this->accesskey, $this->secret);
        $client = new \DefaultAcsClient($iClientProfile);
        \DefaultProfile::addEndpoint($this->area, $this->area, $this->product, $this->domain);
        $request = new Afs\AuthenticateSigRequest();
        // 必填参数，从前端获取，不可更改，android和ios只传这个参数即可
        $request->setSessionId($param['sessionId']);
        // 必填参数，从前端获取，不可更改
        $request->setToken($param['token']);
        // 必填参数，从前端获取，不可更改
        $request->setSig($param['sig']);
        // 必填参数，从前端获取，不可更改
        $request->setScene($param['scene']);
        //必填参数，后端填写
        $request->setAppKey($this->appKey);
        //必填参数，后端填写
        $request->setRemoteIp($this->remoteIp);
        //返回code 100表示验签通过，900表示验签失败
        $response = $client->getAcsResponse($request);
        return $response;
    }


}